package cn.elegent.lockdemo.controller;
import cn.elegent.lock.annotation.ElegentLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 分布式锁的测试工程(注解方式)
 */
@RestController
@Slf4j
public class LockAnnotationController {

	 @GetMapping("/haha")
	    public String haha(String name) {
	        System.out.println(name);
	        //todo: 业务逻辑
	        return name;
	    }
    /**
     * 注解方式加锁
     * @param name
     * @return
     * @throws InterruptedException 
     */
    @GetMapping("/testAnno")
    @ElegentLock(lockName="testAnno",isSpin = true)
    public boolean testLock(String name) throws InterruptedException {
        // 3min 
        Thread.sleep(2000);
        System.out.println(Thread.currentThread().getName()+"-"+name);
        //todo: 业务逻辑
        return true;
    }


}
